package me.zk.practice1.hw;

import java.util.*;

public class Main{

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String[] strings = sc.nextLine().split(",");
        //评论的集合
        List<Node> nodeList = new ArrayList<>();
        Map<Integer, String> map = new HashMap<>();

        for(int i=0; i<strings.length; i+=2){
            //当前评论的内容
            String content = strings[i];
            //当前评论有几个回复
            int child = Integer.valueOf(strings[i+1]);
            //初始化层数
            int row = 1;

            //从后往前遍历
            for(int j=nodeList.size()-1; j>=0; j--){
                Node node = nodeList.get(j);
                if(node.child != 0){
                    //如果这个节点还有子节点，那就属于这个节点
                    node.child --;
                    row = node.row + 1;
                    break;
                }
            }

            Node node = new Node( row, content, child);
            nodeList.add(node);
            map.put( row, map.getOrDefault( row, "") + content + " ");
//            if(map.containsKey(row)){
//                map.get(row) += content + " ";
//            }else {
//                List<String> list = new ArrayList<>();
//                list.add(content);
//                map.put( row, list);
//            }
        }

        for(String str : map.values()){
            System.out.println(str.substring(0, str.length() - 1));
        }

    }

    static class Node{

        private int row;
        private String content;
        private int child;

        /**
         * @param row       评论层数
         * @param content   评论内容
         * @param child     评论回复
         */
        public Node(int row, String content, int child){

            this.row = row;
            this.content = content;
            this.child = child;

        }

    }

}